﻿using AntdUI;
using ImportPlcPointPosition.Enums;
using ImportPlcPointPosition.Extensions;
using SqlSugar;
using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZR.Model;

namespace ImportPlcPointPosition.Models.Table
{
    /// <summary>
	/// 
	/// </summary>
	[SugarTable("cks_plcblockdb")]
    public class PlcBlockDb : BaseEntity
    {
        public PlcBlockDb()
        {
            var btnSave = new AntdUI.CellButton(eOperateBtnType.SaveBtn.ToString(), eOperateBtnType.SaveBtn.GetDisplayDescription(), AntdUI.TTypeMini.Info);
            btnSave.IconSvg = "SaveOutlined";
            var btnDelete = new AntdUI.CellButton(eOperateBtnType.DeleteBtn.ToString(), eOperateBtnType.DeleteBtn.GetDisplayDescription(), AntdUI.TTypeMini.Error);
            btnDelete.IconSvg = "DeleteOutlined";
            _Operate = new AntdUI.CellLink[] { btnSave, btnDelete };
        }


        /// <summary>
        /// 主键
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
        public int Id { get; set; }

      

        /// <summary>
        /// 关联Plc表Id
        /// </summary>
        [SugarColumn(ColumnName = "PlcId")]
        public int PlcId { get; set; }

        /// <summary>
        /// 数据块
        /// </summary>
        [SugarColumn(ColumnName = "BlockDb")]
        public int BlockDb { get; set; }

        /// <summary>
        /// 数据块长度
        /// </summary>
        public int BlockLength { get; set; }

        //private int writeFrom;
        //public int WriteFrom { get => writeFrom;
        //    set
        //    {
        //        writeFrom = value;
        //    }
        //}
        /// <summary>
        /// 写入方:1 PC、2 PLC、3 混合
        /// </summary>
        [SugarColumn(ColumnName = "WriteFrom")]
        public int WriteFrom { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(ColumnName = "Remark")]
        public string Remark { get; set; } = string.Empty;

        /// <summary>
        /// 备注英文
        /// </summary>
        [SugarColumn(ColumnName = "Remark_En")]
        public string Remark_En { get; set; } = string.Empty;

        /// <summary>
        /// 模块 1 上位机 2 AGV
        /// </summary>
        public int Module {  get; set; }

        /// <summary>
        /// 标记,
        /// </summary>
        [SugarColumn(ColumnName = "Flag")]
        public string Flag { get; set; } = "";

        /// <summary>
        /// 是否删除
        /// </summary>
        [SugarColumn(ColumnName = "IsDeleted")]
        public new bool IsDeleted { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        [SugarColumn(ColumnName = "Sequence")]
        public int Sequence { get; set; }

        #region IgnoreProps
        AntdUI.CellLink[] _Operate;
        /// <summary>
        /// 操作
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public AntdUI.CellLink[] Operate
        {
            get => _Operate;
            set
            {
                _Operate = value;
                OnPropertyChanged("Operate");
            }
        }

        /// <summary>
        /// PLC产线代号
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string ProductionLineCode { get; set; }

        /// <summary>
        /// 站点名称
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string WorkstationCode { get; set; }

        /// <summary>
        /// plc备注
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string PlcRemark { get; set; }

        /// <summary>
        /// 写入方
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public CellButton WriteFromCellText
        {
            get
            {
                var text = WriteFrom switch
                {
                    1 => "PC",
                    2 => "PLC",
                    3 => "混合",
                    _ => ""
                };

                return new CellButton("", text)
                {
                    Ghost = true,
                    BorderWidth = 1,
                    //ShowArrow = true,
                    Tooltip="单击下拉选择",
                    DropDownArrow = true,
                    //支持所有单元格控件
                    DropDownItems = new ISelectItem[]{
                        new AntdUI.SelectItem("PC",1),
                        new AntdUI.SelectItem("PLC",2),
                        new AntdUI.SelectItem("混合",3),
                    },
                    DropDownValueChanged = (value) =>
                    {
                        int badge = (value).ObjToInt();
                        WriteFrom = badge;
                        OnPropertyChanged("WriteFromCellText");
                    }
                };

            }
        }

        /// <summary>
        /// 模块选择
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public CellButton ModuleCellText
        {
            get
            {
                var text = Module switch
                {
                    1 => "上位机",
                    2 => "AGV",
                    _ => ""
                };
                return new CellButton("", text)
                {
                    Ghost = true,
                    BorderWidth = 1,
                    //ShowArrow = true,
                    Tooltip = "单击下拉选择",
                    DropDownArrow = true,
                    //支持所有单元格控件
                    DropDownItems = new ISelectItem[]{
                        new AntdUI.SelectItem("上位机",1),
                        new AntdUI.SelectItem("AGV",2),
                    },
                    DropDownValueChanged = (value) =>
                    {
                        int badge = (value).ObjToInt();
                        Module = badge;
                        OnPropertyChanged("ModuleCellText");
                    }
                };

            }
        }

        private bool _IsCheck;

        /// <summary>
        /// 是否选择
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public bool IsCheck {
            get { return _IsCheck; }
            set {
                _IsCheck = value;
                base.OnPropertyChanged();
            }
        }
        #endregion

    }

}
